﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.segments.data_type;
using ConsoleApplication1.segments.field;

namespace ConsoleApplication1.segments
{
    class OBR
    {
        public StringBuilder OBR_ID { get; set; }
        public CM Placer_Order_Number { get; set; }
        public CM Filler_Order_Number { get; set; }
        public CE Universal_Service_ID { get; set; }
        public StringBuilder Priority { get; set; }
        public TS Requested_date_time { get; set; }
        public TS Observation_date_time { get; set; }
        public TS Observation_end_date_time { get; set; }
        public CQ Collection_Volume { get; set; }
        public CN Collector_Identifier { get; set; }
        public StringBuilder Specimen_action_code { get; set; }
        public CE Danger_Code { get; set; }
        public StringBuilder Relevant_clinical_information { get; set; }
        public TS Specimen_received_date_time { get; set; }
        public CM_SPS Specimen_source { get; set; }
        public CN Ordering_Provider { get; set; }
        public StringBuilder Order_Callback_Phone_Number { get; set; }
        public StringBuilder Placer_field_1 { get; set; }
        public StringBuilder Placer_field_2 { get; set; }
        public StringBuilder Filler_Field_1 { get; set; }
        public StringBuilder Filler_Field_2 { get; set; }
        public TS Results_report__status_change_date_time { get; set; }
        public CM_MOC Charge_to_Practice { get; set; }
        public StringBuilder Diagnostic_service_section_ID { get; set; }
        public StringBuilder Result_Status { get; set; }
        public CM_PARENT_RESULT Parent_Result { get; set; }
        public TQ Quantity_timing { get; set; }
        public CN Result_Copies_To { get; set; }
        public CM_EIP Parent_Number { get; set; }
        public StringBuilder Transportation_Mode { get; set; }
        public CE Reason_for_Study { get; set; }
        public CM_NDL Principal_Result_Interpreter { get; set; }
        public CM_NDL Assistant_Result_Interpreter { get; set; }
        public CM_NDL Technician { get; set; }
        public CM_NDL Transcriptionist { get; set; }
        public TS Scheduled_date_time { get; set; }


        public int fill(string source, int temp)
        {
            int i, x = 0;
            for (i = temp; i < source.Length; i++)
            {
                if (source[i] == '|')
                {
                    if (x == 1)
                    {
                        OBR_ID.Capacity = OBR_ID.Length;
                    }
                   else if (x ==5)
                    {
                        Priority.Capacity = Priority.Length;
                    }
                   else if (x ==11)
                    {
                        Specimen_action_code.Capacity = Specimen_action_code.Length;
                    }
                   else if (x == 13)
                    {
                        Relevant_clinical_information.Capacity = Relevant_clinical_information.Length;
                    }
                   else if (x == 17)
                    {
                        Order_Callback_Phone_Number.Capacity = Order_Callback_Phone_Number.Length;
                    }
                   else if (x == 18)
                    {
                        Placer_field_1.Capacity = Placer_field_1.Length;
                    }
                else   if (x == 19)
                    {
                        Placer_field_2.Capacity = Placer_field_2.Length;
                    }
                 else   if (x == 20)
                    {
                        Filler_Field_1.Capacity = Filler_Field_1.Length;
                    }
                  else  if (x == 21)
                    {
                        Filler_Field_2.Capacity = Filler_Field_2.Length;
                    }
                   else if (x == 24)
                    {
                        Diagnostic_service_section_ID.Capacity = Diagnostic_service_section_ID.Length;
                    }
                  else  if (x == 25)
                    {
                        Result_Status.Capacity = Result_Status.Length;
                    }
                  else  if (x == 30)
                    {
                        Transportation_Mode.Capacity = Transportation_Mode.Length;
                    }
                    else if (x==36)
                        return i;
                
                    else
                    {
                        x++;
                        continue;
                    }
                }
                else
                {
                    if (x == 1)  // passing prameter of set id - PID
                    {
                        if (source[i] != '|')
                        {
                            if (OBR_ID == null)
                                OBR_ID = new StringBuilder();
                            OBR_ID.Insert(OBR_ID.Length, source[i]);
                        }
                    }
                    else if (x == 2)
                    {
                        if (source[i] != '|')
                        {
                            if (Placer_Order_Number == null)
                                Placer_Order_Number = new  CM();
                            Placer_Order_Number.fill(source, i);
                        }
                    }
                    else if (x == 3)
                    {
                        if (source[i] != '|')
                        {
                            if (Filler_Order_Number == null)
                                Filler_Order_Number = new  CM();
                            i = Filler_Order_Number.fill(source, i);
                        }
                    }
                    else if (x == 4)
                    {
                        if (source[i] != '|')
                        {
                            if (Universal_Service_ID == null)
                                Universal_Service_ID = new CE ();
                            i = Universal_Service_ID.fill(source, i);
                        }
                    }
                    else if (x == 5)
                    {
                        if (source[i] != '|')
                        {
                            if (Priority == null)
                                Priority = new StringBuilder();
                            Priority.Insert(Priority.Length, source[i]);
                        }
                    }
                    else if (x == 6)
                    {
                        if (source[i] != '|')
                        {
                            if (Requested_date_time == null)
                                Requested_date_time = new TS();
                            i = Requested_date_time.fill(source, i);                    
                        }
                    }
                    else if (x == 7)
                    {
                        if (source[i] != '|')
                        {
                            if (Observation_date_time == null)
                                Observation_date_time = new TS();
                            i = Observation_date_time.fill(source, i);
                        }
                    }
                    else if (x == 8)
                    {
                        if (source[i] != '|')
                        {
                            if (Observation_end_date_time == null)
                                Observation_end_date_time = new  TS ();
                            i = Observation_end_date_time.fill(source, i);
                        }
                    }
                    else if (x == 9)
                    {
                        if (source[i] != '|')
                        {
                            if (Collection_Volume == null)
                                Collection_Volume = new  CQ ();
                            i = Collection_Volume.fill(source, i);
                        }
                    }

                    else if (x == 10)
                    {
                        if (source[i] != '|')
                        {
                            if (Collector_Identifier == null)
                                Collector_Identifier = new  CN ();
                            i = Collector_Identifier.fill(source, i);
                        }
                    }

                    else if (x == 11)
                    {
                        if (source[i] != '|')
                        {
                            if (Specimen_action_code == null)
                                Specimen_action_code = new StringBuilder();
                            Specimen_action_code.Insert(Specimen_action_code.Length, source[i]);
                        }
                    }
                    else if (x == 12)
                    {
                        if (source[i] != '|')
                        {
                            if (Danger_Code == null)
                                Danger_Code = new CE ();
                            i = Danger_Code.fill(source, i);                            
                        }
                    }
                    else if (x == 13)
                    {
                        if (source[i] != '|')
                        {
                            if (Relevant_clinical_information == null)
                                Relevant_clinical_information = new StringBuilder();
                            Relevant_clinical_information.Insert(Relevant_clinical_information.Length, source[i]);
                        }
                    }
                    else if (x == 14)
                    {
                        if (source[i] != '|')
                        {
                            if (Specimen_received_date_time == null)
                                Specimen_received_date_time = new  TS ();
                            i = Specimen_received_date_time.fill(source, i);                                                        
                        }
                    }

                    else if (x == 15)
                    {
                        if (source[i] != '|')
                        {
                            if (Specimen_source == null)
                                Specimen_source = new  CM_SPS ();
                            i = Specimen_source.fill(source, i);                                                                                    
                        }
                    }

                    else if (x == 16)
                    {
                        if (source[i] != '|')
                        {
                            if (Ordering_Provider == null)
                                Ordering_Provider = new  CN ();
                            i = Ordering_Provider.fill(source, i);  
                        }
                    }

                    else if (x == 17)
                    {
                        if (source[i] != '|')
                        {
                            if (Order_Callback_Phone_Number == null)
                                Order_Callback_Phone_Number = new StringBuilder();
                            Order_Callback_Phone_Number.Insert(Order_Callback_Phone_Number.Length, source[i]);
                        }
                    }
                    else if (x == 18)
                    {
                        if (source[i] != '|')
                        {
                            if (Placer_field_1 == null)
                                Placer_field_1 = new StringBuilder();
                            Placer_field_1.Insert(Placer_field_1.Length, source[i]);
                        }
                    }
                    else if (x == 19)
                    {
                        if (source[i] != '|')
                        {
                            if (Placer_field_2 == null)
                                Placer_field_2 = new StringBuilder();
                            Placer_field_2.Insert(Placer_field_2.Length, source[i]);
                        }
                    }
                    else if (x == 20)
                    {
                        if (source[i] != '|')
                        {
                            if (Filler_Field_1 == null)
                                Filler_Field_1 = new StringBuilder();
                            Filler_Field_1.Insert(Filler_Field_1.Length, source[i]);
                        }
                    }
                    else if (x == 21)
                    {
                        if (source[i] != '|')
                        {
                            if (Filler_Field_2 == null)
                                Filler_Field_2 = new StringBuilder();
                            Filler_Field_2.Insert(Filler_Field_2.Length, source[i]);
                        }
                    }

                    else if (x == 22)
                    {
                        if (source[i] != '|')
                        {
                            if (Results_report__status_change_date_time == null)
                                Results_report__status_change_date_time = new  TS ();
                            i = Results_report__status_change_date_time.fill(source, i);  
                        }
                    }

                    else if (x == 23)
                    {
                        if (source[i] != '|')
                        {
                            if (Charge_to_Practice == null)
                                Charge_to_Practice = new  CM_MOC ();
                            i = Charge_to_Practice.fill(source, i);  
                        }
                    }
                    else if (x == 24)
                    {
                        if (source[i] != '|')
                        {
                            if (Diagnostic_service_section_ID == null)
                                Diagnostic_service_section_ID = new StringBuilder();
                            Diagnostic_service_section_ID.Insert(Diagnostic_service_section_ID.Length, source[i]);
                        }
                    }
                    else if (x == 25)
                    {
                        if (source[i] != '|')
                        {
                            if (Result_Status == null)
                                Result_Status = new StringBuilder();
                            Result_Status.Insert(Result_Status.Length, source[i]);
                        }
                    }
                    else if (x == 26)
                    {
                        if (source[i] != '|')
                        {
                            if (Parent_Result == null)
                                Parent_Result = new  CM_PARENT_RESULT ();
                            i = Parent_Result.fill(source, i);  
                        }
                    }
                    else if (x == 27)
                    {
                        if (source[i] != '|')
                        {
                            if (Quantity_timing == null)
                                Quantity_timing = new  TQ ();
                            i = Quantity_timing.fill(source, i);  
                        }
                    }
                    else if (x == 28)
                    {
                        if (source[i] != '|')
                        {
                            if (Result_Copies_To == null)
                                Result_Copies_To = new  CN ();
                            i = Result_Copies_To.fill(source, i);
                        }
                    }
                    else if (x ==29)
                    {
                        if (source[i] != '|')
                        {
                            if (Parent_Number == null)
                                Parent_Number = new  CM_EIP ();
                            i = Parent_Number.fill(source, i);
                        }
                    }
                    else if (x == 30)
                    {
                        if (source[i] != '|')
                        {
                            if (Transportation_Mode == null)
                                Transportation_Mode = new StringBuilder();
                            Transportation_Mode.Insert(Transportation_Mode.Length, source[i]);
                        }
                    }
                    else if (x == 31)
                    {
                        if (source[i] != '|')
                        {
                            if (Reason_for_Study == null)
                                Reason_for_Study = new  CE ();
                            i = Reason_for_Study.fill(source, i);
                        }
                    }
                    else if (x == 32)
                    {
                        if (source[i] != '|')
                        {
                            if (Principal_Result_Interpreter == null)
                                Principal_Result_Interpreter = new  CM_NDL ();
                            i = Principal_Result_Interpreter.fill(source, i);
                        }
                    }
                    else if (x == 33)
                    {
                        if (source[i] != '|')
                        {
                            if (Assistant_Result_Interpreter == null)
                                Assistant_Result_Interpreter = new  CM_NDL ();
                            i = Assistant_Result_Interpreter.fill(source, i);
                        }
                    }
                    else if (x == 34)
                    {
                        if (source[i] != '|')
                        {
                            if (Technician == null)
                                Technician = new  CM_NDL ();
                            i = Technician.fill(source, i);
                        }
                    }
                    else if (x == 35)
                    {
                        if (source[i] != '|')
                        {
                            if (Transcriptionist == null)
                                Transcriptionist = new  CM_NDL ();
                            i = Transcriptionist.fill(source, i);
                        }
                    }
                    else if (x == 36)
                    {
                        if (source[i] != '|')
                        {
                            if (Scheduled_date_time == null)
                                Scheduled_date_time = new  TS ();
                            i = Scheduled_date_time.fill(source, i);
                        }
                    }
                }
            }
            return i;
        }
    }
}
